import { setTheme, defaultTheme } from '../../assets/theme/setTheme'

const user = {
  state: {
    theme: defaultTheme
  },
  mutations: {
    SET_THEME: (state, theme) => {
      state.theme = theme
    }
  },
  actions: {
    // 改变用户主题
    ChangeTheme ({ commit, state }, theme) {
      commit('SET_THEME', theme)
      setTheme(theme)
      // 将用户改变的主题数据，存到缓存的userData里
      let userData = JSON.parse(sessionStorage.getItem('userData'))
      sessionStorage.setItem('userData', JSON.stringify({ ...userData, theme: theme }))
      // 存到数据库（不方便mock所以省略）
    }
  }
}

export default user
